<?php

// 公共助手函数

use app\RedisAdmin;
use Symfony\Component\VarExporter\VarExporter;
use think\Db;
use think\exception\HttpResponseException;
use think\Response;

if (!function_exists('get_my_student')) {

    /**
     * $teacher_id
     * @return string
     */
    function get_my_student($parent_id)
    {
        $student_id = Db::name('parent_bind')->where(['parent_id'=>$parent_id])->column('student_id');
        return $student_id;
    }
}

if (!function_exists('get_admin_id')) {

    /**
     * $teacher_id
     * @return string
     */
    function get_admin_id($user_id)
    {
        $mobile = Db::name('user')->where(['id'=>$user_id])->value('mobile');
        $admin_id = Db::name('admin')->where(['mobile'=>$mobile])->value('id');
        return $admin_id;
    }
}
if (!function_exists('get_grade_name')) {

    /**
     * $grade_id
     * @return string
     */
    function get_grade_name($grade_id)
    {
        $grade_name = RedisAdmin::getInstance(1)->get('get_grade_name_'.$grade_id);
        if(!$grade_name){
            $grade_name = Db::name('grade')->where(['id'=>$grade_id])->value('grade_name');
            RedisAdmin::getInstance(1)->set('get_grade_name_'.$grade_id,$grade_name,60*60*24*60);
        }
        return $grade_name;
    }
}
if (!function_exists('get_school_class_name')) {

    /**
     * $school_class_id
     * @return string
     */
    function get_school_class_name($school_class_id)
    {
        $school_class_name = RedisAdmin::getInstance(1)->get('get_school_class_name_'.$school_class_id);
        if(!$school_class_name){
            $school_class_name = Db::name('school_class')->where(['id'=>$school_class_id])->value('name');
            RedisAdmin::getInstance(1)->set('get_school_class_name_'.$school_class_id,$school_class_name,60*60*24*60);
        }
        return $school_class_name;
    }
}
if (!function_exists('get_teacher_name')) {

    /**
     * $teacher_id
     * @return string
     */
    function get_teacher_name($teacher_id)
    {
        $teacher_name = RedisAdmin::getInstance(1)->get('get_teacher_name_'.$teacher_id);
        if(!$teacher_name){
            $teacher_name = Db::name('admin')->where(['id'=>$teacher_id])->value('nickname');
            RedisAdmin::getInstance(1)->set('get_teacher_name_'.$teacher_id,$teacher_name,60*60*24*60);
        }
        return $teacher_name;
    }
}


if (!function_exists('get_group_id')) {

    /**
     * $teacher_id
     * @return string
     */
    function get_group_id($user_id)
    {
        $mobile = Db::name('user')->where(['id'=>$user_id])->value('mobile');
        $admin_id = Db::name('admin')->where(['mobile'=>$mobile])->value('id');
        $group_id = Db::name('auth_group_access')->where(['uid'=>$admin_id])->value('group_id');
        return $group_id;
    }
}